<?php defined('BASEPATH') OR exit('No direct script access allowed');

	class checklist_class extends CI_Model {
		
		public function list_checklist(){
			if(isset($post['intID'])){
				$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
				$this->db->where(array('intID'=>$intID));
				$this->db->order_by("intID", "asc");
			} else {
				$this->db->order_by("intOrder", "asc");
			}
			
			$query = $this->db->get_where('jtn_check_list',array('intDisabled'=>0));
			if ($query->num_rows() > 0)	{
				$result = $query->result_array();
				return $result;
			} else {
				return 0;
			}
		}
		// user
		public function get_checklist_user($post){
			if(isset($post['intUserID'])){
				$intUserID = stripslashes(filter_var($post['intUserID'], FILTER_SANITIZE_STRING));
				$this->db->where(array('intUserID'=>$intUserID));
			}
			if(isset($post['intID'])){
				$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
				$this->db->where(array('intID'=>$intID));
			}
			if(isset($post['intCheckListID'])){
				$intCheckListID = stripslashes(filter_var($post['intCheckListID'], FILTER_SANITIZE_STRING));
				$this->db->where(array('intCheckListID'=>$intCheckListID));
			}			
			$query = $this->db->get('jtn_check_list_user')->result_array();
			$query = current($query);
			
			if(trim($query['intID'])=="") {
				return 0;
			} else {
				return $query;
			}
		}
		public function list_checklist_user($post){
			if(isset($post['intCheckListID'])){
				$intCheckListID = stripslashes(filter_var($post['intCheckListID'], FILTER_SANITIZE_STRING));
				$this->db->where(array('intCheckListID'=>$intCheckListID));
			}
			if(isset($post['intUserID'])){
				$intUserID = stripslashes(filter_var($post['intUserID'], FILTER_SANITIZE_STRING));
				$this->db->where(array('intUserID'=>$intUserID));
			}
			$this->db->order_by("dateCreatedDate", "asc");
			$query = $this->db->get_where('jtn_check_list_user',array('intDisabled'=>0));
			if ($query->num_rows() > 0)	{
				$result = $query->result_array();
				return $result;
			} else {
				return 0;
			}
		}	
		public function insert_checklist_user($post){
			$intCheckListID = stripslashes(filter_var($post['intCheckListID'], FILTER_SANITIZE_STRING));
			$intUserID = stripslashes(filter_var($post['intUserID'], FILTER_SANITIZE_STRING));
			$strDescription = stripslashes(filter_var($post['strDescription'], FILTER_SANITIZE_STRING));
			$intStatus = stripslashes(filter_var($post['intStatus'], FILTER_SANITIZE_STRING));
				
			$data = array(
					'intCheckListID' => $intCheckListID,
					'intUserID' => $intUserID,
					'strDescription' => $strDescription,
					'intStatus' => $intStatus,
					'intDisabled' => 0,
					'strCreatedby'=>$this->session->userdata('intID'),
					'dateCreatedDate'=>date('Y-m-d H:i:s'),
					'strModifiedBy'=>$this->session->userdata('intID'),
					'dateModifiedDate'=>date('Y-m-d H:i:s')
			);
			
			$this->db->insert('jtn_check_list_user', $data);
			//$message['qry']=$this->db->last_query();
			if($this->db->_error_number()==0)
			{
				$message['fail'] = 0;
				$message['class'] = "success";
				$message['message'] = "Successfully saved.";
				$message['intID'] = $this->db->insert_id();
			}
			else
			{
				$message['fail'] = 1;
				$message['class'] = "error";
				$message['message'] = $message['message'].$this->db->_error_message();;
			}
			return $message;
		}
		public function update_checklist_user($post){
			$intCheckListID = stripslashes(filter_var($post['intCheckListID'], FILTER_SANITIZE_STRING));
			$intUserID = stripslashes(filter_var($post['intUserID'], FILTER_SANITIZE_STRING));
			$strDescription = stripslashes(filter_var($post['strDescription'], FILTER_SANITIZE_STRING));
			$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
		
			$data = array(
					'intCheckListID' => $intCheckListID,
					'intUserID' => $intUserID,
					'strDescription' => $strDescription,
					'strModifiedBy'=>$this->session->userdata('intID'),
					'dateModifiedDate'=>date('Y-m-d H:i:s')
			);
			
			$this->db->where(array('intID'=>$intID));
			$this->db->update('jtn_check_list_user', $data);
			//$message['qry']=$this->db->last_query();
			if($this->db->_error_number()==0)
			{
				$message['fail'] = 0;
				$message['class'] = "success";
				$message['message'] = "Successfully saved.";
				$message['intID'] = $this->db->insert_id();
			}
			else
			{
				$message['fail'] = 1;
				$message['class'] = "error";
				$message['message'] = $message['message'].$this->db->_error_message();;
			}
			return $message;
		}		
		// preload
		public function list_checklist_preload($post){
			$intCheckListID = stripslashes(filter_var($post['intCheckListID'], FILTER_SANITIZE_STRING));
			$this->db->order_by("dateCreatedDate", "asc");
			$query = $this->db->get_where('jtn_check_list_preload',array('intDisabled'=>0,'intCheckListID'=>$intCheckListID));
			if ($query->num_rows() > 0)	{
				$result = $query->result_array();
				return $result;
			} else {
				return 0;
			}
		}
			
		public function update_intstatus_checklist($post){
			$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
			$intStatus = stripslashes(filter_var($post['intStatus'], FILTER_SANITIZE_STRING));
			
			$data = array(
					'intStatus' => $intStatus,
					'strModifiedBy'=>$this->session->userdata('intID'),
					'dateModifiedDate'=>date('Y-m-d H:i:s')
			);
			
			$this->db->where(array('intID'=>$intID));
			$this->db->update('jtn_check_list_user', $data);
			//$message['qry']=$this->db->last_query();
			if($this->db->_error_number()==0)
			{
				$message['fail'] = 0;
				$message['class'] = "success";
				$message['message'] = "Successfully saved.";
				$message['intID'] = $this->db->insert_id();
			}
			else
			{
				$message['fail'] = 1;
				$message['class'] = "error";
				$message['message'] = $message['message'].$this->db->_error_message();;
			}
			return $message;
		}
		public function insert($post){
			$strTitle = stripslashes(filter_var($post['strTitle'], FILTER_SANITIZE_STRING));
			$strImgLink = stripslashes(filter_var($post['strImgLink'], FILTER_SANITIZE_STRING));
		
			$data = array(
					'strTitle' => $strTitle,
					'strImgLink' => $strImgLink,
					'intDisabled' => 0,
					'strCreatedby'=>$this->session->userdata('intID'),
					'dateCreatedDate'=>date('Y-m-d H:i:s'),
					'strModifiedBy'=>$this->session->userdata('intID'),
					'dateModifiedDate'=>date('Y-m-d H:i:s')
			);
		
			$this->db->insert('jtn_check_list', $data);
				
			$this->db->where(array('intID'=>$this->db->insert_id()));
			$this->db->update('jtn_check_list', array('intOrder'=>$this->db->insert_id()));
			//$message['qry']=$this->db->last_query();
			if($this->db->_error_number()==0)
			{
				$message['fail'] = 0;
				$message['class'] = "success";
				$message['message'] = "Successfully saved.";
				$message['intID'] = $this->db->insert_id();
			}
			else
			{
				$message['fail'] = 1;
				$message['class'] = "error";
				$message['message'] = $message['message'].$this->db->_error_message();;
			}
			return $message;
		}		
		public function update($post){
			$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
			$strTitle = stripslashes(filter_var($post['strTitle'], FILTER_SANITIZE_STRING));
			$strImgLink = stripslashes(filter_var($post['strImgLink'], FILTER_SANITIZE_STRING));
		
			$data = array(
					'strTitle' => $strTitle,
					'strImgLink' => $strImgLink,
					'strModifiedBy'=>$this->session->userdata('intID'),
					'dateModifiedDate'=>date('Y-m-d H:i:s')
			);
		
			$this->db->where(array('intID'=>$intID));
			$this->db->update('jtn_check_list', $data);
		
			$this->db->where(array('intID'=>$intID));
			$this->db->update('jtn_check_list', array('intOrder'=>$intID));
			//$message['qry']=$this->db->last_query();
			if($this->db->_error_number()==0)
			{
				$message['fail'] = 0;
				$message['class'] = "success";
				$message['message'] = "Successfully saved.";
				$message['intID'] = $this->db->insert_id();
			}
			else
			{
				$message['fail'] = 1;
				$message['class'] = "error";
				$message['message'] = $message['message'].$this->db->_error_message();;
			}
			return $message;
		}	
		public function delete($post){
			$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
		
			$data = array(
					'intDisabled' => 1,
					'strModifiedBy'=>$this->session->userdata('intID'),
					'dateModifiedDate'=>date('Y-m-d H:i:s')
			);
		
			$this->db->where(array('intID'=>$intID));
			$this->db->update('jtn_check_list', $data);
		
			if($this->db->_error_number()==0)
			{
				$message['fail'] = 0;
				$message['class'] = "success";
				$message['message'] = "Successfully saved.";
				$message['intID'] = $this->db->insert_id();
			}
			else
			{
				$message['fail'] = 1;
				$message['class'] = "error";
				$message['message'] = $message['message'].$this->db->_error_message();;
			}
			return $message;
		}
		public function get_checklist($post){
			$intID=0;
			if(isset($post['intID'])){
				$intID = $post['intID'];
			}
			$intID = stripslashes(filter_var($intID, FILTER_SANITIZE_STRING));
			$query = $this->db->get_where('jtn_check_list',array('intID'=>$intID))->result_array();
			$query = current($query);
		
			if(trim($query['intID'])=="") {
				return 0;
			} else {
				return $query;
			}
		}		
	} // end class
?>